import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sinosheets/components/no_data_widget.dart';
import 'package:sinosheets/pages/estimate/shipping_line/widget/shipping_line_cell.dart';

import 'logic.dart';

class ShippingLinePage extends StatefulWidget {
  const ShippingLinePage({Key? key}) : super(key: key);

  @override
  State<ShippingLinePage> createState() => _ShippingLinePageState();
}

class _ShippingLinePageState extends State<ShippingLinePage> {
  final ShippingLineLogic logic = Get.put(ShippingLineLogic());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ShippingLineLogic>(builder: (get) {
      return Scaffold(
        appBar: AppBar(
          title: Text('shipping_line'.tr),
          elevation: 0,
          centerTitle: false,
        ),
        body: Padding(
          padding: EdgeInsets.symmetric(horizontal: 10.r, vertical: 10.r),
          child: get.sortList.isEmpty
              ? NoDataWidget.emptyList(
                  title: 'No Shipping Lines',
                  description: 'No shipping lines available at the moment. Please try again later.',
                  showButton: false,
                )
              : CustomScrollView(
                  slivers: [
                    SliverList.separated(
                      itemCount: get.sortList.length,
                      itemBuilder: (context, index) {
                        return ShippingLineCell(lineMap: get.sortList[index], type: ShippingLineType.list);
                      },
                      separatorBuilder: (context, index) {
                        return SizedBox(height: 12.r);
                      },
                    ),
                  ],
                ),
        ),
      );
    });
  }

  @override
  void dispose() {
    Get.delete<ShippingLineLogic>();
    super.dispose();
  }
}
